package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.Greedy;

/**
 * @author tzp
 * @since 2020/10/17
 */
public class LC860 implements Greedy {
    public boolean lemonadeChange(int[] bills) {
        int fiveNums = 0, tenNums = 0;
        for (int i = 0; i < bills.length; i++) {
            if (bills[i] == 5) {
                fiveNums++;
            } else if (bills[i] == 10) {
                fiveNums--;
                if (fiveNums < 0) return false;
                tenNums++;
            } else {
                if (tenNums >= 1) {
                    tenNums = tenNums - 1;
                    fiveNums = fiveNums - 1;
                } else {
                    fiveNums = fiveNums - 3;
                }
                if (fiveNums < 0) return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new LC860().lemonadeChange(new int[]{5, 10, 5}));
        System.out.println(new LC860().lemonadeChange(new int[]{5, 5, 10, 10, 20}));
    }
}
